<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // 1.鸡免同笼:总共100个脚，各多少只?列出所有可能性。
    /* for (let x = 0; x <= 50; x++) {
        for (let y = 0; y <= 25; y++) {
            if (x * 2 + y * 4 == 100) {
                document.write('鸡有' + x + '只;兔有' + y + '只<br>');
            }
        }
    } */

    /* 2.计算100-1000的水仙花数
    个位的3次方+十位的三次方+百位的三次方=这个数本身 */
    /* for (var i = 100; i < 1000; i++) {
        var ge = i % 10;
        var bai = parseInt(i / 100);//=Math.floor(i/100);
        var shi = parseInt((i - bai * 100) / 10);//Math.floor(i/10)%10;
        var num = ge ** 3 + bai ** 3 + shi ** 3;
        if (i == num) {
            document.write(i + '&nbsp;');
        }
    } */

    /* 3.计算出斐波那契数列第20位,从第一位到第20位的数据都添加到数组当中
    1 1 2 3 5 8 13 21 34 */
    var arr=[1,1];
    for (let i = 0; i < 18; i++) {
        arr[i+2]=arr[i]+arr[i+1];
    }
    console.log(arr);
    document.write(arr);

    // 4.冒泡排序
    /* var arr1 = [34, 14, 56, 3, 69, 45, 30, 7];
    for (let j = 0; j < arr1.length; j++) {
        for (let i = 0; i < arr1.length - j-1; i++) {
            if (arr1[i] > arr1[i + 1]) {
                arr1[i] = arr1[i] + arr1[i + 1];
                arr1[i + 1] = arr1[i] - arr1[i + 1];
                arr1[i] = arr1[i] - arr1[i + 1];
            }
            console.log(arr1);
        }
    }
    document.write(arr1); */

    //5.选择排序
    /* var arr1 = [34, 14, 56, 3, 69, 45, 30, 7];
    var k;
    for (let j = 0; j < arr1.length - 1; j++) {
        k = j;
        for (let i = j + 1; i < arr1.length; i++) {
            if (arr1[i] > arr1[j]) {
                k = i;
            }
        }
        arr1[j] = arr1[k] + arr1[j];
        arr1[k] = arr1[j] - arr1[k];
        arr1[j] = arr1[j] - arr1[k];
        console.log(arr1);
    }
    document.write(arr1); */
</script>

</html>